import { type OrderTyle } from "@/types/consult";
import { defineStore } from "pinia";
// import DictAPI, { type DictVO, type DictData } from "@/api/system/dict";
// import { setDictCache, getDictCache } from "@/utils/cache";
export const LoginPinia = defineStore("Login", () => {
  const tab = ref(true);
  const okZC1 = ref(false);
  const okZC2 = ref(false);
  const zcBol = ref(false);
  const user = reactive([
    { id: "0", phone: "15690000000", password: "123456" },
    { id: "1", phone: "15690000001", password: "123456" },
  ]);

  function changeZcBol() {
    zcBol.value = true;
  }
  function jump() {
    uni.navigateTo({ url: "/pages/register/index" });
    localStorage.clear();
  }

  function qhCart() {
    localStorage.clear();
    tab.value = !tab.value;
  }

  function pushUser(value: any) {
    user.push(value);
  }

  function switching() {
    // if (tab.value) {
    //   console.log(okZC1.value);
    //   okZC1.value = okZC1.value;
    // } else {
    console.log(okZC2.value);
    okZC2.value = true;
    // }
  }

  //病情暂存地
  const zc = reactive([{ description: "", time: "", record: "", img: [] }]);
  //暂存地新
  const zcT = reactive<OrderTyle[]>([]);
  //点击下一步将患者病情放到zc中
  function tjZc(value: any) {
    zc.push(value);
    zcT.unshift(value);
  }

  // 患者信息
  const ManagePatients = reactive([
    { name: "张三", sex: "男", age: "32", identity: "130432200411240022" },
    { name: "杨如画", sex: "女", age: "32", identity: "130432200411220023" },
    { name: "李富贵", sex: "男", age: "31", identity: "130432198911240032" },
  ]);
  //默认患者
  const defaultA = ref(0);
  // 选择患者样式
  const selectPatient = ref(0);
  //修改默认患者
  function changeDefault(value: any) {
    defaultA.value = value;
  }
  //修改选中患者样式
  function changeSelectPatient(value: any) {
    selectPatient.value = value;
  }
  //添加患者
  function addManagePatients(value: any) {
    ManagePatients.push(value);
  }
  //默认支付方式
  //0代表微信，1代表支付宝
  const method = ref(0);
  //支付方式
  const methodData = reactive([
    { img: "@/static/wx.png", name: "微信支付" },
    { img: "@/static/zfb.png", name: "支付宝" },
  ]);
  //修改默认支付方式
  function changeMethod(value: any) {
    method.value = value;
  }
  //所有患者信息

  // 搜索推荐信息
  const hotList = ref<string[]>(["胃肠炎", "胃溃疡", "低血压"]);

  //问诊记录
  const record = ref<OrderTyle[]>([]);
  //添加问诊记录
  function addRecord(value: OrderTyle) {
    record.value.unshift(value);
  }
  function replaceRecord(value: OrderTyle) {
    record.value.splice(0, 1);
    record.value.unshift(value);
  }
  function delRecord() {
    record.value.splice(0, 1);
  }
  // 科室暂存区
  const selectDepartment = ref();
  function addSelectDepartment(value: string) {
    selectDepartment.value = value;
  }
  // 咨询费用暂存区
  const zixun = ref();
  function addZixun(value: any) {
    zixun.value = value;
  }
  return {
    changeZcBol,
    zcBol,
    tab,
    jump,
    qhCart,
    okZC1,
    okZC2,
    switching,
    user,
    pushUser,
    tjZc,
    zc,
    ManagePatients,
    defaultA,
    changeDefault,
    method,
    methodData,
    changeMethod,
    addManagePatients,
    hotList,
    zcT,
    record,
    addRecord,
    replaceRecord,
    delRecord,
    addSelectDepartment,
    selectDepartment,
    selectPatient,
    changeSelectPatient,
    zixun,
    addZixun,
  };
});
